﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Telerik.Web.Mvc;

namespace ShippingID.Controllers
{
    public class CheckpointEntregaController : Controller
    {
        private BL.ServiceCheckPointEntrega bl ;
        public CheckpointEntregaController()
        {
            bl = new BL.ServiceCheckPointEntrega();
        }

        public ActionResult Index()
        {
            Telerik.Web.Mvc.GridModel g = new GridModel();
            return View((new BL.ServiceGeral().RetornarTodos<Modelo.CheckPointEntrega>()));
        }

        //
        // GET: /CheckpointEntrega/Details/5

        public ActionResult Details(int id)
        {
            return View((new BL.ServiceGeral().RetornarPorID<Modelo.CheckPointEntrega>(id)));
        }

        //
        // GET: /CheckpointEntrega/Create

        public ActionResult Create()
        {
            return View();
        } 

        //
        // POST: /CheckpointEntrega/Create

        [HttpPost]
        public ActionResult Create(Modelo.CheckPointEntrega modelo)
        {
            int idEntrega = Convert.ToInt32(Session["idEntrega"]);
            modelo.IdEntrega = idEntrega;

            if (ModelState.IsValid && bl.Gravar(modelo))
            {
                return RedirectToAction("Index");
            }

            return View(modelo);
        }
        
        //
        // GET: /CheckpointEntrega/Edit/5
 
        public ActionResult Edit(int id)
        {
            return View();
        }

        //
        // POST: /CheckpointEntrega/Edit/5

        [HttpPost]
        public ActionResult Edit(int id, Modelo.CheckPointEntrega modelo)
        {
            if (ModelState.IsValid)
            {
                new BL.ServiceGeral().Alterar<Modelo.CheckPointEntrega>(modelo);
                return RedirectToAction("Index");
            }

            return View(modelo);
        }

        //
        // GET: /CheckpointEntrega/Delete/5
 
        public ActionResult Delete(int id)
        {
            return View();
        }

        //
        // POST: /CheckpointEntrega/Delete/5

        [HttpPost]
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                new BL.ServiceGeral().Excluir<Modelo.CheckPointEntrega>(id);
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
    }
}
